/*
 * Created by Jesse Phillips
 * Created on Feb 25, 2006
 */
/**
 * Queue using an array.
 */
public class ArrayQueue {
	public char[] stack;
	private int start, end;

	/**
	 * Builds an array of size, and starts at the end.
	 * 
	 * @param size how big the queue is to be.
	 */
	public ArrayQueue(int size) {
/*ans bl*/
		stack = new char[size+1];
		end = 0;
		start = size;
/*ans ab*/
	}

	/**
	 * Places a item (char) onto the queue
	 * 
	 * @param item what is to be enqued
	 */
	public void enque(char item) {
/*ans bl*/
		if(!isFull()) {
			int mod = (end+stack.length-1)%stack.length;
			end = mod;
			stack[end] = item;
		}
/*ans ab*/
	}

	/**
	 * Removes an item from the queue.
	 * 
	 * @return The char in the queue, 0 if empty.
	 */
	public char deque() {
		if(!isEmpty()) {
			char popped = stack[start];
			int mod = (start+stack.length-1)%stack.length;
			start = mod;
			return popped;
		}
		return 0;
	}

	/**
	 * Returns the fullness of the queue.
	 * 
	 * @return boolean
	 */
	public boolean isFull() {
		return ((end+stack.length-2)%stack.length) == start;
	}

	/**
	 * Returns the emptyness of the queue.
	 * 
	 * @return boolean
	 */
	public boolean isEmpty() {
		int mod =(end+stack.length-1)%stack.length;
		return mod == start;
	}
}
